| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import { NextRequest, NextResponse } from 'next/server';
- import { ImportProcessor } from '@/app/lib/excel-import/import-processor';
- export async function POST(
- request: NextRequest,
- { params }: { params: Promise<{ id: string }> }
- ) {
- try {
- // Await the params promise to get the actual params
- const resolvedParams = await params;
- const importId = parseInt(resolvedParams.id);
- if (isNaN(importId)) {
- return NextResponse.json(
- { success: false, error: 'Invalid import ID' },
- { status: 400 }
- );
- }
- // Initialize import processor
- const processor = new ImportProcessor();
- // Validate import before processing
- const validation = await processor.validateImport(importId);
- if (!validation.valid) {
- return NextResponse.json(
- { success: false, error: validation.errors.join(', ') },
- { status: 400 }
- );
- }
- // Start processing in background
- processor.processImport(importId).catch(error => {
- console.error('Import processing failed:', error);
- });
- return NextResponse.json({
- success: true,
- message: 'Import process started successfully',
- importId
- });
- } catch (error) {
- console.error('Error triggering import:', error);
- return NextResponse.json(
- { success: false, error: 'Failed to trigger import' },
- { status: 500 }
- );
- }
- }
|